package com.ssm.sfzy.controller;
import com.ssm.sfzy.constant.CommonConstant;
import com.ssm.sfzy.entity.ConsultProblem;
import com.ssm.sfzy.entity.CourseProblem;
import com.ssm.sfzy.service.ConsultProblemService;
import com.ssm.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/consultProblem")
public class ConsultProblemController {

    @Autowired
    private ConsultProblemService consultProblemService;

    @GetMapping("/find")
    public Object find(
            @RequestParam(defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
            @RequestParam(defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize,
            ConsultProblem consultProblem
    ){
        Map<String, Object> map = consultProblemService.findPage(pageNum, pageSize,consultProblem);
        return  Result.success(map);
    }


    @GetMapping("/findById/{id}")
    public Object findById(@PathVariable Integer id){
        ConsultProblem courseProblem= consultProblemService.findById(id);
        return Result.success(courseProblem);
    }


    @PostMapping("/add")
    public Object add(@RequestBody ConsultProblem consultProblem) throws Exception {
        consultProblemService.add(consultProblem);
        return Result.success(consultProblem);
    }

    @PutMapping("/edit")
    public Object edit(@RequestBody ConsultProblem consultProblem) throws Exception {
        consultProblemService.edit(consultProblem);
        return Result.success(consultProblem);
    }
    @DeleteMapping("/remove/{id}")
    public Object remove(@PathVariable Integer id){
        consultProblemService.remove(id);
        return Result.success(id);
    }

    @DeleteMapping("/removeBatch/{ids}")
    public Object removeBatch(Integer[] ids){
        consultProblemService.removeBatch(ids);
        return Result.success(ids);
    }
    @GetMapping("/getByTeacherId/{id}")
    public Object getByTeacherId(@PathVariable Integer id){
        List<ConsultProblem> consultProblems = consultProblemService.getByTeacherId(id);

        return Result.success(consultProblems);
    }

}

